/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.gallsoft.amidar;

import android.graphics.Point;

/**
 * A system for testing positions against "hot spots" embedded in the level tile map data.
 * A level may contain a layer of "hot spots," tiles that provide a hint to the game objects about
 * how to act in that particular area of the game world.  Hot spots are commonly used to direct AI
 * characters, or to define areas where special collision rules apply (e.g. regions that cause
 * instant death when entered).
 */
public class HotSpotSystem extends BaseObject {
    GameWorld mWorld;
    int lastJunction = -1;

    public class HotSpotType {
        public static final int NONE = 0;
        public static final int GO_RIGHT = 1;
        public static final int GO_LEFT = 2;
        public static final int GO_UP = 4;
        public static final int GO_DOWN = 8;        
    }
    
    public HotSpotSystem() {
        super();
    }
    
    @Override
    public void reset() {
    	mWorld =  null;
    }
    
    public final void setWorld(GameWorld world) {
    	mWorld = world;
    }
    
    public int getHotSpot(Vector2 position, int newDir) {
        int result = HotSpotType.NONE;
        
        
        if (mWorld != null) {
        	int junctionID = mWorld.getJunctionID(position.x, position.y, newDir);
        	
        	if (junctionID >= 0) {
        		result = mWorld.getDirections(junctionID);
        		lastJunction = junctionID;
        	}
        }
        return result;
    }
    
    public Vector2 getLastJunction() {
    	Point junc = mWorld.getJunction(lastJunction);
    	Vector2 juncVector = new Vector2(junc.x, junc.y);
    	
    	return juncVector;
    }
    
    
}
